package com.tanhua.server.controller;

import com.tanhua.server.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/smallVideos")
public class VideoController {

    @Autowired
    private VideoService videoService;

    @GetMapping
    public ResponseEntity<Object> smallVideos(@RequestParam(defaultValue = "1")Integer page, @RequestParam(defaultValue = "10")Integer pagesize){
        return ResponseEntity.ok(videoService.queryVideos(page,pagesize));
    }

    @PostMapping
    public ResponseEntity<Object> uploadVideo(MultipartFile videoThumbnail, MultipartFile videoFile, String text) throws IOException {
        return videoService.uploadVideo(videoThumbnail,videoFile,text);
    }

    @PostMapping("{uid}/userFocus")
    public ResponseEntity<Object> userFocus(@PathVariable("uid") Long followUserId){
        return videoService.userFocus(followUserId);
    }

    @PostMapping("/{uid}/userUnFocus")
    public ResponseEntity<Object> userUnFocus(@PathVariable("uid") Long followUserId){
        return videoService.userUnFocus(followUserId);
    }
}
